package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualitySchemeConfigurationDto;
import com.pureut.quality.domain.vo.QualitySchemeConfigurationVo;
import com.pureut.quality.service.QualitySchemeConfigurationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 检验方案配置表控制层
 * Author:C
 * Date:2023/02/02 17:10
 * @DESC
 */
@RestController
@RequestMapping("/quality-scheme-configuration")
public class QualitySchemeConfigurationController extends BaseController {

    @Resource
    QualitySchemeConfigurationService qualitySchemeConfigurationService;


    /**
     * 检验方案配置列表
     */
    @RequiresPermissions("quality:verifyconfig:inspecscheme:list")
    @GetMapping("/list")
    public TableDataInfo getList(QualitySchemeConfigurationVo qualitySchemeConfigurationVo) {
        startPage();
        //查询检验方案配置列表
        List<QualitySchemeConfigurationDto> list = qualitySchemeConfigurationService.getSchemeConfigurationList(qualitySchemeConfigurationVo);
        return getDataTable(list);
    }

    /**
     * 检验方案配置新增
     */
    @RequiresPermissions("quality:verifyconfig:inspecscheme:add")
    @PostMapping("/add")
    @Log(title = "检验方案配置新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody QualitySchemeConfigurationVo qualitySchemeConfigurationVo) throws Exception {
        return toAjax(qualitySchemeConfigurationService.add(qualitySchemeConfigurationVo));
    }

    /**
     * 检验方案配置查看
     */
    @RequiresPermissions("quality:verifyconfig:inspecscheme:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") long id) {
        return AjaxResult.success(qualitySchemeConfigurationService.view(id));
    }

    /**
     * 检验方案配置修改
     */
    @RequiresPermissions("quality:verifyconfig:inspecscheme:edit")
    @PutMapping("/update")
    @Log(title = "检验方案配置修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@Validated @RequestBody QualitySchemeConfigurationVo qualitySchemeConfigurationVo) {
        return toAjax(qualitySchemeConfigurationService.updateConfiguration(qualitySchemeConfigurationVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("quality:verifyconfig:inspecscheme:remove")
    @DeleteMapping("/delete/{idStr}")
    @Log(title = "检验方案配置删除", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable("idStr") String idStr) {
        return toAjax(qualitySchemeConfigurationService.delete(idStr));
    }

    /**
     * 检验是否配置方案
     */
    @PostMapping("/check")
    public boolean check(@RequestBody QualitySchemeConfigurationVo qualitySchemeConfigurationVo) {
        return qualitySchemeConfigurationService.check(qualitySchemeConfigurationVo);
    }
}
